home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload Trio 2
/
Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO
/
dir43
/
med300.zip
/
MEREFORM.CLA
< prev
next >
Wrap
Text File
|
1994-02-22
|
6KB
|
169 lines
!▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
!█ █
!█ MEREFORM.CLA █
!█ Document and paragraph reformatting █
!█ █
!█ Revision Number: 1 █
!█ Revision Date : 22-Feb-94 █
!█ █
!█ Revision History █
!█ 1 Created █
!█ █
!▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
MEMBER('MEMOEDIT')
!─────────────────────────────────────────────────────────────────────────
! Local Module MAP
!─────────────────────────────────────────────────────────────────────────
MAP
ME_Chars(),USHORT ! Count characters in buffer
.
!═══════════════════════════════════════════════════════════════════════
! Returns number of characters in document (less trailing spaces)
!═══════════════════════════════════════════════════════════════════════
ME_Chars FUNCTION
! Locals:
ulLastChar ULONG ! Last character offset
usNChars USHORT ! Number of characters
ubChar BYTE ! Character code
CODE
ulLastChar = MED:ulEditBuffer + (MED:usMaxChars - 1)
usNChars = MED:usMaxChars !
LOOP WHILE usNChars !
PEEK(ulLastChar, ubChar) !
IF ubChar <> 20H THEN BREAK. !
ulLastChar -= 1 !
usNChars -= 1 !
. !
RETURN( usNChars + 1 )
!═══════════════════════════════════════════════════════════════════════
! Determine line break position
!═══════════════════════════════════════════════════════════════════════
ME_LineBreak FUNCTION( usOffset, usMaxWidth )
! Locals:
ulAddress ULONG ! Address
usIndex USHORT ! Offset
usSavPos USHORT ! Saved offset
usWidth USHORT ! Line width
ubChar BYTE ! Character
bbSpaceFlag BYTE ! Space flag
CODE
usIndex = usOffset ! Set initial values
usSavPos = usIndex !
usWidth = 0 !
bbSpaceFlag = 0 !
LOOP WHILE usIndex < MED:usCharacters ! Loop for each character
ulAddress = MED:ulEditBuffer + usIndex ! Form address
PEEK(ulAddress, ubChar) ! Get character code
usWidth += 1 ! Update line width
IF usWidth >= usMaxWidth ! If line too long
IF bbSpaceFlag THEN usIndex = usSavPos + 1.! Stop at last space
BREAK ! Break
ELSIF ubChar = eHRt ! Else if HRt
usIndex += 1 ! Stop at HRt
BREAK ! Break
ELSIF ubChar = 20H ! Elsif space character
usSavPos = usIndex ! Save position
bbSpaceFlag = 1 ! Set flag
. ! Endif
usIndex += 1 ! Update index
. ! End loop
IF usIndex > usOffset ! Return line break position
RETURN( usIndex - usOffset ) !
ELSE !
RETURN( 1 ) !
. !
!═══════════════════════════════════════════════════════════════════════
! Reformat entire document
!═══════════════════════════════════════════════════════════════════════
ME_ReformDoc PROCEDURE
! Locals:
usOffset SHORT ! Buffer offset
CODE
MED:usCharacters = ME_Chars() ! Set character count
FREE(qLine) ! Free line table
usOffset = 0 ! Start at first char
QLN:bbRedisplay = 1 ! Save first table entry
QLN:usLineStart = usOffset !
ADD(qLine) !
LOOP ! Loop
usOffset += ME_LineBreak(usOffset, MED:usLineWidth)
IF usOffset >= MED:usCharacters THEN BREAK. ! Break if past last char
QLN:bbRedisplay = 1 ! Save line table entry
QLN:usLineStart = usOffset !
ADD(qLine) !
. ! End loop
RETURN
!═══════════════════════════════════════════════════════════════════════
! Reformat from current position until line break sync
!═══════════════════════════════════════════════════════════════════════
ME_ReformPar PROCEDURE( usOffset )
! Locals:
usLineIndex USHORT ! Line index
usSyncDelay USHORT ! Sync delay count
bbSyncFlag BYTE ! Sync flag
CODE
usLineIndex = ME_LineIndex( usOffset ) ! Set initial values
usSyncDelay = 1 !
bbSyncFlag = 0 !
IF usLineIndex > 1 ! If not at first line
usLineIndex -= 1 ! Start at previous line
usSyncDelay += 1 ! and compensate sync
. ! Endif
GET(qLine, usLineIndex) ! Get line start
usOffset = QLN:usLineStart !
QLN:bbRedisplay = 1 ! Set current line
DO UpdateTable ! for redisplay
LOOP ! Loop
usOffset += ME_LineBreak(usOffset, MED:usLineWidth)
IF usOffset >= MED:usCharacters THEN BREAK. ! Break if past last char
usLineIndex += 1 ! Update line index
GET(qLine, usLineIndex) ! If line sync established
IF (usOffset = QLN:usLineStart) AND (usSyncDelay = 0)
bbSyncFlag = 1 ! Set flag
BREAK ! Break
. ! Endif
IF usSyncDelay THEN usSyncDelay -= 1. ! Decrement delay count
QLN:usLineStart = usOffset ! Update line table entry
QLN:bbRedisplay = 1 !
DO UpdateTable !
. ! End loop
IF (NOT bbSyncFlag) ! If sync not established
LOOP WHILE usLineIndex < RECORDS(qLine) ! Remove extra table entries
GET(qLine, RECORDS(qLine)) !
DELETE(qLine) !
. . ! Endif
RETURN
!──────────────────────────────────────────────────────────────────────────
UpdateTable ROUTINE ! Update line table
!──────────────────────────────────────────────────────────────────────────
IF usLineIndex > RECORDS(qLine) ! If index not in table range
ADD(qLine) ! Add new entry
ELSE ! Else
PUT(qLine) ! Update existing entry
. ! Endif